package com.zwjlg.baselibrary;

import android.content.Context;
import android.content.res.AssetManager;
import android.text.TextUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

/**
 * ================================================
 * <p>
 * Created by ligang on 2021/3/16 10:31
 * ================================================
 */
public class AUtils {
    public static <T> boolean isEmpty(List<T> list) {
        return list == null || list.size() == 0;
    }

    public static String readAssetsFile(Context context, String assetsName) {
        if (TextUtils.isEmpty(assetsName)) {
            return null;
        }
        AssetManager assetManager = context.getAssets();
        try {
            InputStream inputStream = assetManager.open(assetsName);
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
            String line = null;
            StringBuffer sb = new StringBuffer();
            boolean isFirstLine = true;
            while ((line = br.readLine()) != null) {
                if (isFirstLine) {
                    isFirstLine = false;
                } else {
                    sb.append("\n");
                }
                sb.append(line);
            }
            return sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
